<?php
date_default_timezone_set('PRC');

define('BASE_PATH', str_replace('\\', '/', realpath(__DIR__ . '/')) . "/");

//记录开始时间
list($t1, $t2) = explode(' ', microtime());
$stime = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
define('STIME', $stime);

//功能模检索
$appPath = realpath(__DIR__) . '/app';
$dirs = scandir($appPath);
$apps = [];
foreach ($dirs as $d) {
    if (is_dir($appPath . '/' . $d) && $d != '.' && $d != '..')
        $apps[] = $d;
}
define('APP_DIRS', json_encode($apps));

$ishttps = false;
if (isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS'])))
    $ishttps = true;
elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT']))
    $ishttps = true;
$httpType = $ishttps ? 'https://' : 'http://';

define('DOMAIN', $_SERVER['HTTP_HOST']);
define('BASE_URL', $httpType . DOMAIN);
define('CUR_URL', BASE_URL . $_SERVER["REQUEST_URI"]);
define('RES_URL', BASE_URL);
defined('YII_DEBUG') or define('YII_DEBUG', true);
define("IS_PRO",false);
defined('YII_ENV') or define('YII_ENV', 'dev');

if (YII_ENV === 'dev') {
    ini_set("display_errors", "On");
    error_reporting(E_ALL | E_STRICT);
}

define('PATH_ROOT', __DIR__ . '/');
define('PATH_APP', __DIR__ . '/app');
define('PATH_COMMON', __DIR__ . '/common');

require(PATH_ROOT . '/vendor/autoload.php');
require(PATH_ROOT . '/vendor/yiisoft/yii2/Yii.php');


require(PATH_COMMON . '/config/bootstrap.php');
$config = require(PATH_COMMON . '/config/main.php');

//session_start();
try {
    $application = new yii\web\Application($config);
} catch (\yii\base\InvalidConfigException $e) {
}

require(PATH_COMMON . '/cm/cm.php');
$application->run();